package com.example.yls.myapplication;

import android.media.AudioManager;
import android.media.SoundPool;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
    private Button btnLoad;
    private Button btnPlay2;
    private Button btnPlay3;
    private Button btnPlay4;
    private Button btnPlay5;
    private Button btnPlay6;
    private int[] soundIdArr = new int[5];
    private SoundPool soundPool;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btnLoad = findViewById(R.id.playLoad);
        btnPlay2 =findViewById(R.id.play2);
        btnPlay3 =findViewById(R.id.play3);
        btnPlay4 =findViewById(R.id.play4);
        btnPlay5 =findViewById(R.id.play5);
        btnPlay6 =findViewById(R.id.play6);
        btnLoad.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                soundPool = new SoundPool(10, AudioManager.STREAM_MUSIC,0);
                soundIdArr[0] = soundPool.load(MainActivity.this,R.raw.chimes,1);
                soundIdArr[1] = soundPool.load(MainActivity.this,R.raw.ding,1);
                soundIdArr[2] = soundPool.load(MainActivity.this,R.raw.enter,1);
                soundIdArr[3] = soundPool.load(MainActivity.this,R.raw.ringout,1);
                soundIdArr[4] = soundPool.load(MainActivity.this,R.raw.notify,1);
            }
        });
        btnPlay2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                soundPool.play(soundIdArr[0],1,1,1,0,1);
            }
        });
        btnPlay3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                soundPool.play(soundIdArr[1],1,1,1,0,1);
            }
        });
        btnPlay4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                soundPool.play(soundIdArr[2],1,1,1,0,1);
            }
        });
        btnPlay5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                soundPool.play(soundIdArr[3],1,1,1,0,1);
            }
        });
        btnPlay6.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                soundPool.play(soundIdArr[4],1,1,1,0,1);
            }
        });
    }
}
